<extend name="Public/base"/>

<block name="style">
  <link rel="stylesheet" type="text/css" href="__CSS__/order.css" media="all">
</block>

<block name="body">
  <!-- 标题 -->
  <div class="main-title">
    <h2>
      <notempty name="_GET['uid']">
        {$_GET['uid']|get_nickname}的
      </notempty>
      <notempty name="sdp_uid">
        {$sdp_uid|get_nickname}的分销
      </notempty>
      订单列表({$_total})
    </h2>
  </div>
  <!-- 按钮工具栏 -->
  <div class="cf">
    <div class="fl">
      <!-- <button class="btn ajax-post confirm" target-form="ids" url="{:U('Order/cancel')}">取 消</button>
      <a href="javascript:order.bestmart();" class="btn">灵通打单</a> -->
      <a class="btn" href="{:U('index')}">刷 新</a>
    </div>
    <!-- 高级搜索 -->
    <form action="{:U()}" method="GET" id="J_search_form">
      <div class="search-form fr cf">
        <div class="sleft">
          <input type="text" name="store" class="search-input w-120" value="{:I('store')}" placeholder="店铺名称">
        </div>
        <div class="fl">
          <if condition="C('SDP_IS_OPEN')">
            <select name="is_sdp">
              <option value="0">全部订单</option>
              <option value="1">分销订单</option>
            </select>
          </if>
          <select name="order_type">
              <option value="0">所有订单</option>
              <option value="1">普通订单</option>
              <option value="2">团购订单</option>
            </select>
          <select id="o_status" name="o_status">
            <option value="-2">订单状态</option>
            <option value="0">待付款</option>
            <option value="-3">已付款</option>
            <option value="-1">交易取消</option>
            <optgroup label="已付款">
              <option value="200">待发货</option>
              <option value="201">待买家收货</option>
              <option value="202">交易成功</option>
            </optgroup>
            <optgroup label="退款">
              <option value="300">待处理退款申请</option>
              <option value="301">待买家退货</option>
              <option value="302">待退款</option>
              <option value="303">退款成功</option>
              <option value="304">平台退款中</option>
              <option value="404">系统取消订单</option>
              <option value="405">退款驳回</option>
            </optgroup>
          </select>
        </div>
        <div class="sleft">
          <select id="time_type" name="time_type" class="fl">
            <option value="create_time">下单时间</option>
            <option value="payment_time">支付时间</option>
          </select>
          <input type="text" name="start_time" class="search-input w-100 date_select" value="{:I('get.start_time')}" placeholder="开始"/>
          <span class="fl line-h">至</span>
          <input type="text" name="end_time" class="search-input w-100 date_select" value="{:I('get.end_time')}" placeholder="结束"/>
        </div>
        <div class="sleft">
          <input type="text" name="keywords" class="search-input input-2x" value="{:I('keywords')}" placeholder="订单编号">
          <input type="text" name="ship" class="search-input input-2x" value="{:I('ship')}" placeholder="收货人姓名或收货人手机号">
          <a class="sch-btn" href="javascript:;" id="J_search"><i class="btn-search"></i></a>
        </div>
      </div>
      <notempty name="_GET.uid">
        <input type="hidden" name="uid" value="{:I('get.uid')}" />
      </notempty>
      <notempty name="sdp_uid">
        <input type="hidden" name="sdp_uid" value="{$sdp_uid}" />
      </notempty>
    </form>
  </div>
  <!-- 数据表格 -->
  <table class="order-table-head">
    <tr>
      <th width="30">
         <input class="checkbox check-all" type="checkbox">
      </th>
      <th width="350">订单基本信息</th>
      <th width="110" class="text-right">订单总额</th>
      <th width="110" class="text-right">第三方支付金额</th>
      <th>&nbsp;</th>
      <th width="360">状态</th>
    </tr>
  </table>
  <notempty name="list">
    <volist name="list" key='key' id="vo">
      <table class="order-table">
        <tr>
          <th colspan="9">
            <span class="text-cancel">下单时间：</span>
            {$vo.payment.create_time|time_format}
            <if condition="current($vo['order'])['payment_time']">
              <span class="text-cancel">支付时间：</span>
              {:time_format(current($vo['order'])['payment_time'])}
            </if>
            <if condition="$vo.is_sdp eq true">
                <span class="order-sdp">分销</span>
            </if>
            <span class="split-tab"></span>
            <span class="text-cancel">下单用户：</span>
            <a href="{:U('User/view?id='.$vo['payment']['uid'])}">{$vo.payment.uid|get_nickname}</a>
            <span class="split-tab"></span>
            <span class="text-cancel">收货人：</span>
            {$vo.ship.ship_uname} 
            <span class="split-tab"></span>
            {$store[$vo['store_id']]['store_name']}
            <eq name="vo.payment.payment_status" value="1">
              <span class="fr">
                <span class="text-cancel">支付方式：</span>
                <if condition="$vo['payment']['payment_type'] eq '' OR ($vo['payment']['payment_amount'] eq 0 AND $vo['payment']['finance_amount'] gt 0)">
                  余额支付
                  <else/>
                  {:get_payment_type_text($vo['payment']['payment_type'])}
                </if>
                <if condition="IS_SUPPLIER eq false">
                <a href="javascript:;" onclick="UI.load('{:U('Payment/preview?payment_id='.$vo['ship']['payment_id'])}');">[详情]</a>
                </if>
              </span>
            </eq>
            <eq name="vo.invoice_need" value="1">
            <span class="order-sdp">索要发票</span>
            </eq>
            <volist name="vo.order" id="data">

            <if condition='$data.order_type neq 1 '>
               <span class="order-sdp">
                <switch name='data.order_type'>
                    <case value='2'>团购订单</case>
                </switch>
               </span>
            </if>
            </volist>
          </th>
        </tr>
        <volist name="vo.store_order" id="data" key="k">
          <tr>
            <if condition="$k eq count($vo.store_order)">
            <td width="20" rowspan="{:count($vo['store_order'])}" class="text-center{$data['supplier_ids'] == 0 ? ' is-pai-order' :'' }">
              <input name="ids[]" class="ids" type="checkbox" value="{$data['id']}"> 
            </td>
            </if>
            <td width="130" class="item-lists">
              <foreach name="data.item_ids_arr" item="item">
                <a href="{:U('/Item/detail?id='.$item)}" target="_blank"><img src="{:get_image_thumb(get_cover(get_item_images($item), 'path'), 60, 60)}" title="{$item|get_item_name}"></a>
              </foreach>
            </td>
            <if condition="$k eq count($vo.store_order)">
            <td width="210" rowspan="{:count($vo['store_order'])}">订单号：{$data.order_sn}<!-- <a href="{:U('view?id='.$data['id'])}">{$data.order_sn}</a> --></td>
            </if>
            <if condition="$k eq count($vo.store_order)">
            <td width="100" class="text-right" rowspan="{:count($vo['store_order'])}">{:sprintf('%.2f', $vo['order'][$data['old_order_id']]['total_amount']+$vo['order'][$data['old_order_id']]['finance_amount'])} 元</td>
            <td width="100" class="text-right" rowspan="{:count($vo['store_order'])}"><span class="text-danger">{$vo['order'][$data['old_order_id']].total_amount}</span>元</td>
            </if>
            <td width="200" class="text-center">商品来源：{:get_store_text($data['store_ids']);}</td>
            <td class="text-right">
              {$data.o_status_text}<span class="split-tab"></span>
            </td>
            <td width="80" class="text-center">
              {$data.is_packed_text}
            </td>
            <td width="140" class="text-center">
                <a href="{:U('view?id='.$data['id'])}">[查看]</a>
              </td>
            </td>
          </tr>
        </volist>
      </table>
    </volist>
    <div class="page">
      {$_page}
    </div>
  <else/>
  <div class="list-empty">
    暂无订单！
  </div>
  </notempty>
</block>

<block name="script">
  <script src="__PUBLIC__/Admin/js/My97Date/WdatePicker.js"></script>
  <script type="text/javascript">
    $(function(){
      //设置单选，复选，下拉菜单的值
      Core.setValue('is_sdp', '{:I("get.is_sdp")}');
      Core.setValue('o_status', '{$o_status|default = ""}');
      Core.setValue('order_type', '{$order_type|default = ""}');
      Core.setValue('time_type', '{$time_type|default = ""}');
      //时间选择
      $('.date_select').focus(function(){
        WdatePicker({skin: 'twoer', dateFmt: 'yyyy-MM-dd', maxDate: '%y-%M-%d'});
      });
      //导航高亮
      highlight_subnav("{:U('index')}");
    });
  </script>
</block>